<?php
	defined('RUN') or die('No access');

	class UserModel
	{
		public function getByUsername($username)
		{
			$condition = array(
					'field' => 'username',
					'value' => strtolower($username)
				);

			$users = Model::getData('users', '*', $condition);

			if (count($users) > 0)
				return $users[0];

			return FALSE;
		}

		public function getById($id)
		{
			$condition = array(
					'field' => 'id',
					'value' => $id
				);

			$users = Model::getData('users', '*', $condition);

			if (count($users) > 0)
				return $users[0];

			return FALSE;
		}

		public function checkAuth($username, $password)
		{
			$user = $this->getByUsername($username);

			if ($user)
			{
				if ($user['password'] == Security::hash($password))
				{
					unset($user['password']);

					return $user;
				}
			}

			return FALSE;
		}
	}
